using Microsoft.AspNetCore.Hosting;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using KG.SystemService;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

namespace KGprogramV1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var webhost = CreateHostBuilder(args).Build();
            using (var scope = webhost.Services.CreateScope())
            {
                NodeService nodeService = scope.ServiceProvider.GetService<NodeService>();
                RelationService relationService = scope.ServiceProvider.GetService<RelationService>();
            }
            webhost.Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    var builder = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile(System.AppDomain.CurrentDomain.BaseDirectory + "appsettings.json");
                    var config = builder.Build();
                    var url = config["WebApi:applicationUrl"];
                    webBuilder.UseUrls(url).UseStartup<Startup>();
                });
    }
}
